package PCClient2;



import PCClient2.MyClass.ReqType;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @Author: 0162977
 * @Date: 2020/12/2 16:28
 */
public class ShareSpaceAndFun {
    public static int myPort = 4011;
    public static int portMainLocal = 4021;

    private static int count=0;
    private static List<ReqType> reqList = new ArrayList<ReqType>();

    private static AtomicBoolean notify = new AtomicBoolean(false);

    public static void success(){
        count = count+1;
    }
    public static int getCount(){
        return count;
    }

    public static void addReqMap(String website){
        ReqType req = new ReqType();
        req.setWebsite(website);
        req.setTimeStamp(new Date().getTime());

        while (!notify.compareAndSet(false,true)){;}
        reqList.add(req);

        notify.set(false);

    }


    public static void checkResult(String website,String Ip){

        String res = website.split("\\.")[0];
        String[] resIp = Ip.split("\\.");
        if (Integer.parseInt(res)!=(Integer.parseInt(resIp[1])*1000 + Integer.parseInt(resIp[2])*200 +Integer.parseInt(resIp[3]))){
            System.out.println("解析失败");
            return;
        }

        while (!notify.compareAndSet(false,true)){;}
        for (int i=0 ;i<reqList.size();i++){
            if (reqList.get(i).getWebsite().equals(website)){
                reqList.remove(i);
                i = i-1;
                count = count +1;
            }
        }
        notify.set(false);
    }
}
